Thread: Having a ||CLANG: Error: linker command failed with exit code 1||

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    1

    Unhappy Having a ||CLANG: Error: linker command failed with exit code 1||

    gcc error message looks like this:
    Code:
     gcc k-hw1.c -lm -Wall -WerrorUndefined symbols for architecture x86_64:
      "_Comm", referenced from:
          _main in t-ebc1-ff9c31.o
      "_Ind", referenced from:
          _main in k-ebc1-ff9c31.o
      "_Res", referenced from:
          _main in k-ebc1-ff9c31.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation) 
    This is my first time ever coding and I've been scratching my head at this problem for as good couple of hours and I have no idea what I am doing at this point.

    The code I used was this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    
    
    int menu();
    int Res();
    int Comm();
    int Ind();
    
    
    
    
    int main ()
    {
    {
    int menu ();
    }
            int conType;
    
    
    
    
             {
            printf("******Electricity Bill Calculator******\n\n");
            printf("1. Residential\n");
            printf("2. Commercial\n");
            printf("3. Industial\n\n");
            printf("0. quit program\n\n");
            printf("Choose the type of connection: \n");
            scanf("%d", &conType);
    do
            switch (conType)
            {
            case 1: Res();
            break;
    
    
    
    
            case 2: Comm();
            break;
    
    
    
    
            case 3: Ind();
            break;
    
    
    
    
            default:
            printf("Invalid Choice! Please enter a valid choice: \n");
            break;
            }
            while (conType != 0);
             }
    int Res();
    
    
            int unit, enCharge, total;
            float cuCharge;        printf("Enter the number of units (in kWh): \n");
            scanf("%d", &unit);
    
    
    if (unit>=0 && unit<=300)
            {
            enCharge=unit*.075;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>=301 && unit<=750)
    
    
            {
            enCharge=unit*.10;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>=751 && unit <=1550)
    
    
            {
            enCharge=unit*.1350;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>1501)
    
    
            {
    
    
            enCharge=unit*.15;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    int Comm();
    
    
    if (unit>=0 && unit<=300)
            {
            enCharge=unit*.300;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>=301 && unit<=750)
    
    
            {
          enCharge=unit*.14;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>=751 && unit <=1550)
    
    
            {
            enCharge=unit*.1750;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>1501)
    
    
            {
    
    
            enCharge=unit*.20;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    int Ind();
    
    
    if (unit>=0 && unit<=300)
            {
            enCharge=unit*.36;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>=301 && unit<=750)
    
    
            {
            enCharge=unit*.40;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    else if (unit>=751 && unit <=1550)
    
    
            {
            enCharge=unit*.4550;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    else if (unit>1501)
    
    
            {
    
    
            enCharge=unit*.50;
            cuCharge=unit/(float)10;
    
    
            total = enCharge+cuCharge;
            }
    
    
    printf("Total Amount = %d", total);
    
    
    exit (0);
    }


    Last edited by brycefu; 02-19-2016 at 02:17 AM. Reason: text color

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You declared the functions named Res, Comm and Ind, but you did not define (implement) them.

    Anyway, you need to indent your code properly.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2015
    Location
    Bangalore, Karnataka, India
    Posts
    34
    The code look very ugly. It is very hard to understand which curly bracket starts where and ends where.
    Anyways as you will do more and more coding you yourself will start managing the code well.

    As pointed by laserlight, you have declared the functions int menu(), int Res(), int Comm(), int Ind()

    int menu();
    int Res();
    int Comm();
    int Ind();

    but where is the definition ???

    The definitions should go something like this:

    Code:
    int menu(){
        /* 
         * Some line of code
         * 
         */
    }
    You define other functions also.

    Also, the do while(); in your does not have a curly braces, may be you will get an error later.
    Do while code should go like this:

    Code:
    do
    {
        /* some code */
    } while ();
    

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker Error In Template Code
    By nickman in forum C++ Programming
    Replies: 8
    Last Post: 01-27-2015, 01:24 PM
  2. need assistance with a valgrind error within clang
    By saldar05 in forum C Programming
    Replies: 2
    Last Post: 03-04-2013, 01:59 AM
  3. Replies: 2
    Last Post: 07-13-2011, 06:50 AM
  4. make: Fatal error: Command failed for target `clean'
    By vaibhavs17 in forum C++ Programming
    Replies: 5
    Last Post: 02-02-2011, 04:37 AM
  5. what is the command to exit xfce?
    By msenthil in forum Linux Programming
    Replies: 3
    Last Post: 01-10-2008, 06:04 AM

Tags for this Thread